#ifndef KLIB_H
#define KLIB_H

#include <stdarg.h>
#include "types.h"

static inline uint32_t down2(uint32_t size,uint32_t bound){
        return size & ~(bound-1);
}
//can't ignore the rest of bound
static inline uint32_t up2(uint32_t size,uint32_t bound){
        return (size+bound-1) & ~(bound-1);
}

void kernel_strcpy(char *dest,const char *src);
void kernel_strncpy(char *dest,const char *src,unsigned int size);
int kernel_strlen(const char *str);
//int kernel_strcmp(const char *str1,const char *str2);
int kernel_strncmp(const char *str1,const char *str2,unsigned int size);

void kernel_strcat(char *str1,const char *str2);
void kernel_strncat(char *str1,const char *str2,unsigned int size);

void kernel_memcpy(void *dest,const void *src,unsigned int size);
void kernel_memset(void *dest,unsigned char val,unsigned int size);
void kernel_memmove(void *dest,const void *src,unsigned int size);
int kernel_memcmp(const void *str1,const void *str2,unsigned int size);

void kernel_sprintf(char *buff,const char *fmt,...);
void kernel_vsprintf(char *buff,const char *fmt,va_list args);

void kernel_itoa(char *str,int num,int base);

char * get_file_name(const char * str);
int strings_count(char ** argv);

#ifndef RELEASE
#define ASSERT(expr)                      \
        if (!(expr)) panic(__FILE__,__LINE__,__func__,#expr)                
void panic(const char * file,int line, const char * func, const char * cond);
#else
#define ASSERT(expr)   ((void)0)
#endif

#endif